﻿namespace Agent
{
    using Agent.Dialogs;
    using OpenVPN;
    using OpenVPN.States;
    using System;
    using System.CodeDom.Compiler;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.Threading;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Markup;

    [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
    public class StatusWindow : Window, IDisposable, IComponentConnector
    {
        public EventHandler<LogEventArgs> a;
        public EventHandler<TmpFileLogEventArgs> b;
        private SynchronizationContext c;
        internal Label d;
        internal Button e;
        internal Button f;
        internal Button g;
        internal Border h;
        internal ScrollViewer i;
        internal TextBox j;
        private bool k;
        [CompilerGenerated]
        private ConnectionButton l;

        public StatusWindow(string A_0, VPNConnectionState A_1)
        {
            this.InitializeComponent();
            this.c = SynchronizationContext.Current;
            this.a = new EventHandler<LogEventArgs>(this.Logs_LogEvent);
            this.b = new EventHandler<TmpFileLogEventArgs>(this.LogFile_LogEvent);
            this.j.Text = A_0;
            this.i.ScrollToBottom();
            this.c();
            this.c(A_1);
            if (ConfigManager.r() || (AgentUser.a().b() == LicenseType.Limited))
            {
                this.e.IsEnabled = false;
            }
        }

        private void btnDisconnect_Click(object A_0, RoutedEventArgs A_1)
        {
            if ((this.d() != null) && this.d().g().p())
            {
                this.d().g().k();
                base.Close();
            }
            else if (((this.d() != null) && !this.d().g().p()) && (this.d().g().l().State.CreateSnapshot().ConnectionState == VPNConnectionState.Stopped))
            {
                this.d().g().i();
            }
        }

        private void btnReconnect_Click(object A_0, RoutedEventArgs A_1)
        {
            if ((this.d() != null) && this.d().g().p())
            {
                this.d().g().t();
            }
        }

        private void btnSend_Click(object A_0, RoutedEventArgs A_1)
        {
            SendMessage message = new SendMessage(this.d());
            ConfigManager.a(message);
        }

        private void c()
        {
            this.d.Content = e.c("Disconnected");
            this.f.Content = e.c("Disconnect");
            this.g.Content = e.c("Reconnect");
            this.e.Content = e.c("Send");
            base.Title = e.c("StatusWindowTitle");
        }

        private void c(VPNConnectionState A_0)
        {
            SendOrPostCallback d = null;
            SendOrPostCallback callback2 = null;
            SendOrPostCallback callback3 = null;
            SendOrPostCallback callback4 = null;
            SendOrPostCallback callback5 = null;
            switch (A_0)
            {
                case VPNConnectionState.Initializing:
                    if (d == null)
                    {
                        d = new SendOrPostCallback(this.g);
                    }
                    this.c.Send(d, null);
                    return;

                case VPNConnectionState.Running:
                    if (callback2 == null)
                    {
                        callback2 = new SendOrPostCallback(this.f);
                    }
                    this.c.Send(callback2, null);
                    return;

                case VPNConnectionState.Stopping:
                    if (callback4 == null)
                    {
                        callback4 = new SendOrPostCallback(this.d);
                    }
                    this.c.Send(callback4, null);
                    return;

                case VPNConnectionState.Stopped:
                    if (callback3 == null)
                    {
                        callback3 = new SendOrPostCallback(this.e);
                    }
                    this.c.Send(callback3, null);
                    return;

                case VPNConnectionState.Error:
                    if (callback5 == null)
                    {
                        callback5 = new SendOrPostCallback(this.c);
                    }
                    this.c.Send(callback5, null);
                    return;
            }
        }

        [CompilerGenerated]
        private void c(object A_0)
        {
            this.d.Content = e.c("Error");
            this.g.IsEnabled = true;
            this.f.Content = e.c("Disconnect");
        }

        [EditorBrowsable(EditorBrowsableState.Never), DebuggerNonUserCode]
        private void c(int A_0, object A_1)
        {
            switch (A_0)
            {
                case 1:
                    this.d = (Label) A_1;
                    return;

                case 2:
                    this.e = (Button) A_1;
                    this.e.Click += new RoutedEventHandler(this.btnSend_Click);
                    return;

                case 3:
                    this.f = (Button) A_1;
                    this.f.Click += new RoutedEventHandler(this.btnDisconnect_Click);
                    return;

                case 4:
                    this.g = (Button) A_1;
                    this.g.Click += new RoutedEventHandler(this.btnReconnect_Click);
                    return;

                case 5:
                    this.h = (Border) A_1;
                    return;

                case 6:
                    this.i = (ScrollViewer) A_1;
                    return;

                case 7:
                    this.j = (TextBox) A_1;
                    return;
            }
            this.k = true;
        }

        [CompilerGenerated]
        private void d(object A_0)
        {
            this.d.Content = e.c("Disconnecting");
            this.g.IsEnabled = false;
            this.f.Content = e.c("Connect");
        }

        public void Dispose()
        {
        }

        [CompilerGenerated]
        private void e(object A_0)
        {
            this.d.Content = e.c("Disconnected");
            this.g.IsEnabled = false;
            this.f.Content = e.c("Connect");
        }

        [CompilerGenerated]
        private void f(object A_0)
        {
            this.d.Content = e.c("Connected");
            this.g.IsEnabled = true;
            this.f.Content = e.c("Disconnect");
        }

        [CompilerGenerated]
        private void g(object A_0)
        {
            this.d.Content = e.c("Connecting");
            this.g.IsEnabled = false;
            this.f.Content = e.c("Disconnect");
        }

        [DebuggerNonUserCode]
        public void InitializeComponent()
        {
            if (!this.k)
            {
                this.k = true;
                Uri resourceLocator = new Uri("/TheSafety;component/statuswindow.xaml", UriKind.Relative);
                Application.LoadComponent(this, resourceLocator);
            }
        }

        private void LogFile_LogEvent(object A_0, TmpFileLogEventArgs A_1)
        {
            <>c__DisplayClassb classb;
            TmpFileLogEventArgs b = A_1;
            this.c.Send(new SendOrPostCallback(classb.c), null);
        }

        private void Logs_LogEvent(object A_0, LogEventArgs A_1)
        {
        }

        public void SetStatus(object A_0, StateChangedEventArgs A_1)
        {
            this.c(A_1.NewState.ConnectionState);
        }

        public ConnectionButton ConnectionBtn
        {
            [CompilerGenerated]
            get
            {
                return this.l;
            }
            [CompilerGenerated]
            set
            {
                this.l = value;
            }
        }
    }
}

